package org.openzip.openzip.unpacking.model;

import java.io.File;
import java.io.IOException;
import java.util.Collection;
import java.util.jar.JarFile;
import java.util.zip.ZipEntry;

import org.openzip.openzip.unpacking.util.JarToFolderCopier;

public class OpenZipUnpacker implements IOpenZipUnpacker
{
	@Override public void unpack(File path, Collection<ZipEntry> files){
		JarToFolderCopier jtf = new JarToFolderCopier();
		
		
		
		
		
		String jarFileName = OpenZipUnpacker.class.getProtectionDomain().getCodeSource().getLocation().getFile();
		
		
		//Uncomment HERE! to work in JAR
		JarFile jarFile = null;
		try {
			jarFile = new JarFile(jarFileName);
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		/*
		//Uncomment HERE! to work with your own external JAR
		JarFile jarFile = null;
		try {
			jarFile = new JarFile("/root/workspace/OpenZIP/sample/out.jar");
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		*/
		System.out.println("Kopirujem do: " + path.getAbsolutePath());
		
		jtf.copy(jarFile, path);
		
		System.out.println("Melo by byt zkopirovano.. ");

	}
}
